package com.jinyu.jyly.ui.mine.buy;

import android.app.Activity;

import com.jinyu.jyly.base.BasePresenter;
import com.jinyu.jyly.bean.AllInfoBean;
import com.jinyu.jyly.net.DataManager;

import rx.Subscription;
import rx.functions.Action1;

public class MineBuyPresenter extends BasePresenter<MineBuyContract.View> implements MineBuyContract.Presenter {

    public MineBuyPresenter(Activity activity, MineBuyContract.View view) {
        super(activity, view);

    }

    /**
     * 我的订单
     * @param param
     */
    @Override
    public void getOrderList(String param) {
        Subscription subscribe = DataManager.getInstance().getOrderList(param)
                .subscribe(new Action1<AllInfoBean>() {
                    @Override
                    public void call(AllInfoBean InfoData) {
                        if (InfoData != null) {
                            mView.onOrderList(InfoData);
                        }
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        throwable.printStackTrace();
                        mView.onFailer(throwable);
                    }
                });
        addSubscribe(subscribe);
    }

    /**
     * 我的订单
     * @param param
     */
    @Override
    public void getPageOrderList(String param) {
        Subscription subscribe = DataManager.getInstance().getPageOrderList(param)
                .subscribe(new Action1<AllInfoBean>() {
                    @Override
                    public void call(AllInfoBean InfoData) {
                        if (InfoData != null) {
                            mView.onPageOrderList(InfoData);
                        }
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        throwable.printStackTrace();
                        mView.onFailer(throwable);
                    }
                });
        addSubscribe(subscribe);
    }

    /**
     * 更新订单状态
     * @param param
     */
    @Override
    public void getChangeOrder(String param) {
        Subscription subscribe = DataManager.getInstance().getChangeOrder(param)
                .subscribe(new Action1<AllInfoBean>() {
                    @Override
                    public void call(AllInfoBean InfoData) {
                        if (InfoData != null) {
                            mView.onChangeOrder(InfoData);
                        }
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        throwable.printStackTrace();
                        mView.onFailer(throwable);
                    }
                });
        addSubscribe(subscribe);
    }

    /**
     * 待转拍
     * @param param
     */
    @Override
    public void setChangeOrder(String param) {
        Subscription subscribe = DataManager.getInstance().setChangeOrder(param)
                .subscribe(new Action1<AllInfoBean>() {
                    @Override
                    public void call(AllInfoBean InfoData) {
                        if (InfoData != null) {
                            mView.onSetChangeOrderState(InfoData);
                        }
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        throwable.printStackTrace();
                        mView.onFailer(throwable);
                    }
                });
        addSubscribe(subscribe);
    }

    /**
     * 确认收货
     * @param param
     */
    @Override
    public void setChangeShouHuo(String param) {
        Subscription subscribe = DataManager.getInstance().setChangeShouHuo(param)
                .subscribe(new Action1<AllInfoBean>() {
                    @Override
                    public void call(AllInfoBean InfoData) {
                        if (InfoData != null) {
                            mView.onChangeShouHuo(InfoData);
                        }
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        throwable.printStackTrace();
                        mView.onFailer(throwable);
                    }
                });
        addSubscribe(subscribe);
    }


}
